describe("SeeTransactionDetailController in SG", function() {

    var controller = null;
    var objE = null;

    beforeEach(function() {
        objE = new BreezeException({
            errorCode: 123,
            errorMessage: 'error'
        });

        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();

        App.SeeTransactionDetailController.reopen({

            init: function() {
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
            }

        });
        controller = App.SeeTransactionDetailController.create();
    });

    describe("prepareController method", function() {

        it("should invoke getPaymentHistoryDetails when Transaction is PaymentTransaction", function() {
            var transaction = App.PaymentTransaction.create();
            spyOn(App.Router, 'getParameter').andReturn(transaction);
            spyOn(controller, 'showLoading');
            spyOn(App.api_paymentHistoryDetail, 'getPaymentHistoryDetails');

            controller.prepareController();

            expect(App.Router.getParameter).toHaveBeenCalled();
            expect(controller.showLoading).toHaveBeenCalled();
            expect(App.api_paymentHistoryDetail.getPaymentHistoryDetails).toHaveBeenCalled();
        });

        it("should invoke getPaymentHistoryDetails when Transaction is AccountTransaction", function() {
            var transaction = App.AccountTransaction.create();
            spyOn(App.Router, 'getParameter').andReturn(transaction);

            controller.prepareController();

            expect(controller.get('transaction')).toEqual(transaction);
        });

    });

    describe("callback method", function() {

        it("callback success", function() {
            var transaction = App.BaseTransaction.create();
            spyOn(controller, 'hideLoading');

            controller.callback(transaction, null);

            expect(controller.get('transaction')).toEqual(transaction);
            expect(controller.hideLoading).toHaveBeenCalled();
        });

        it("callback error", function() {
            spyOn(controller, 'hideLoading');

            controller.callback(null, objE);

            expect(controller.get('transaction')).toEqual(null);
            expect(controller.hideLoading).toHaveBeenCalled();
        });

    });
});